package com.ets.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.ets.dao.PaperDao;
import com.ets.entity.*;
@Repository
public class PaperDaoImpl extends BaseDaoImpl implements PaperDao {
	//Get paper by Id.
	@Override
	public Paper getPaperById(int id) {
		String hql="from Paper where id="+id;
		return (Paper) getSession().createQuery(hql).uniqueResult();
	}
	
	//Get all papers.
	@SuppressWarnings("unchecked")
	@Override
	public List<Paper> getAll() {
		String hql="from Paper";
		return getSession().createQuery(hql).list();
	}

	//Update existed paper
	@Override
	public void update(Paper paper) {
		Session session=getSession();
		session.merge(paper);
		session.flush();
		session.close();
		
	}

	//Delete paper.
	@Override
	public void delete(int id) {
		Session session=getSession();
		session.delete(session.get(Paper.class, id));
		session.flush();
		session.close();
		
	}

}
